package com.yidu.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yidu.dao.LockerBoxMapper;
import com.yidu.model.LockerBox;
import com.yidu.service.BoxService;
import com.yidu.util.Pages;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author roots
 * @since 2018-10-20
 */
@Service
public class BoxServiceImpl implements BoxService {
	@Resource
	LockerBoxMapper boxmap;
	

	/**
	 * 查询所有
	 */
	@Override
	public List<LockerBox> selectAll(LockerBox lockerbox,Pages pages) {
		System.out.println("查询所有servic="+lockerbox.getBoxId());
		Map<String, Object> map =new HashMap<>();
		map.put("area", lockerbox);
		map.put("pages", pages);
		return boxmap.selectAll(map);
	}

	@Override
	public LockerBox findlIdAll(String id) {
		return boxmap.selectByPrimaryKey(id);
	}
	

	/**
	 * 增加还是删除
	 */
	@Override
	public int addorupdate(LockerBox lockerbox) {
		System.out.println("sssss==="+lockerbox.getBoxId());
		if(lockerbox.getBoxId()!=null && !"".equals(lockerbox.getBoxId())) {
			System.out.println("asdasd进入了修改的方法");
			return boxmap.updateByPrimaryKeySelective(lockerbox);
		}else {
			System.out.println("asdasdasd进入了增加的方法");
			String uuid=UUID.randomUUID().toString().replace("-", "");
			lockerbox.setBoxId(uuid);
			return boxmap.insertSelective(lockerbox);
		}
	}
	
	/**
	 * 删除
	 */
	@Override
	public int deletes(String boxId) {
		System.out.println("deleteservice");
		return boxmap.deleteByPrimaryKey(boxId);
	}

	/**
	 * 根据id查询所有
	 */
	@Override
	public List<LockerBox> selectidAll(LockerBox lockerbox) {
		System.out.println("查询某地区所有柜子service");
		return boxmap.selectidAll(lockerbox);
	}

	@Override
	public int updateId(String id) {
		return boxmap.updateId(id);
	}

	@Override
	public int oneup(String id) {
		return boxmap.oneup(id);
	}
	

	/**
	 * 分页
	 */
	@Override
	public int findCount2(LockerBox lockerBox) {
		int rows=boxmap.findCount2(lockerBox);
		return rows;
	}

	@Override
	public LockerBox selectboxid(String id) {
		return boxmap.selectboxid(id);
	}
}
